package com.znjc.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.znjc.device.domain.IotDataCheckRuleRef;
import com.znjc.device.mapper.IotDataCheckRuleRefMapper;
import com.znjc.device.service.IIotDataCheckRuleRefService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author zengpc
 * @date 2023-12-04
 */
@Service
public class IotDataCheckRuleRefServiceImpl extends ServiceImpl<IotDataCheckRuleRefMapper, IotDataCheckRuleRef> implements IIotDataCheckRuleRefService {

    @Override
    public List<Long> getIdList(Long id, int tag) {
        LambdaQueryWrapper<IotDataCheckRuleRef> wrapper = new LambdaQueryWrapper<>();
        if (tag == 0) {
            wrapper.eq(IotDataCheckRuleRef::getResRuleId, id);
        } else {
            wrapper.eq(IotDataCheckRuleRef::getDataCheckId, id);
        }
        List<IotDataCheckRuleRef> list = this.list(wrapper);
        if (CollectionUtils.isNotEmpty(list)) {
            if (tag == 0) {
                return list.stream().map(IotDataCheckRuleRef::getDataCheckId).collect(Collectors.toList());
            } else {
                return list.stream().map(IotDataCheckRuleRef::getResRuleId).collect(Collectors.toList());
            }
        }
        return null;
    }
}
